import json
from flask import request

from flask import Response


class FlaskResponse:

    def __init__(self, status, message, result):
        self.status = status
        self.message = message
        self.result = result


def errorResp(message):
    return Response(json.dumps(dict(status=500, message=message),
                               default=lambda obj: obj.__dict__,
                               sort_keys=True,
                               indent=None,
                               ensure_ascii=False), mimetype='application/json')
    #如果是返回pretty josn indent=4


def successResp(result):
    return Response(json.dumps(dict(status=200, result=result),
                               default=lambda obj: obj.__dict__,
                               sort_keys=True,
                               indent=None,
                               ensure_ascii=False), mimetype='application/json')


def getData() -> dict:
    data = request.get_data()
    try:
        data = json.loads(data.decode("utf-8"))
    except:
        data = None
    finally:
        return data
